package br.com.itc.componentes.containers
{
	import br.com.itc.componentes.util.PopUpUtil;
	
	import mx.containers.TitleWindow;
	import mx.core.UIComponent;
	import mx.effects.Move;
	import mx.effects.Parallel;
	import mx.events.EffectEvent;
	import mx.events.FlexEvent;
	import mx.managers.IFocusManagerComponent;
	
	public class Janela extends TitleWindow
	{
		
		public static const FECHAR_JANELA:String = "fecharJanela";
		
		public function Janela()
		{
			this.addEventListener(FlexEvent.CREATION_COMPLETE, init);
			this.showCloseButton = true;
		}
		
		private function init(event: FlexEvent): void {
			var componente: UIComponent;
			for each(componente in this.getChildren()) {
				if(componente is CanvasITC) {
					var canvas: CanvasITC = componente as CanvasITC;
					var componenteCanvas: UIComponent;
					var focusHabilitado: Boolean = false;
					for each(componenteCanvas in canvas.getChildren()) {
						if (componenteCanvas is IFocusManagerComponent) {
							componenteCanvas.setFocus();
							focusManager.showFocus();
							focusHabilitado = true;
							break;
						}
					}
					if (focusHabilitado) {
						break;
					}
				}
			}
		}
		
		public function fechaJanela(): void{
			var animMove:Move = new Move();
			animMove.yTo = 	this.y - 20;
			
			var anim:Parallel = new Parallel(this);
			anim.children = [animMove];
			anim.duration = 300;
			anim.play();
			anim.addEventListener(EffectEvent.EFFECT_END, removePopUp);
		}
		
		private function removePopUp(evt:EffectEvent):void{
			PopUpUtil.fecharJanela(this);
			
		}
		
		/*
		* MÉTODOS Gets / Sets
		*/
		
		public function set titulo(value: String): void{
			title = value;
		}
		public function get titulo(): String{
			return title;
		}
		
		public function set iconeTitulo(value: Class): void{
			titleIcon = value;
		}
		public function get iconeTitulo(): Class{
			return titleIcon;
		}
	}
}